define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'extension/order/index' + location.search,
                    add_url: 'extension/order/add',
                    edit_url: 'extension/order/edit',
                    del_url: 'extension/order/del',
                    multi_url: 'extension/order/multi',
                    import_url: 'extension/order/import',
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'goods_sn', title: __('Goods_sn'), operate: 'LIKE'},
                        {field: 'order.order_sn', title: __('Order.order_sn'), operate: 'LIKE'},
                        {field: 'order.game', title: __('Order.game'), operate: 'LIKE'},
                        {field: 'order.plat', title: __('Order.plat'), operate: 'LIKE'},
                        {field: 'order.area', title: __('Order.area'), operate: 'LIKE'},
                        {field: 'order.server', title: __('Order.server'), operate: 'LIKE'},
                        {field: 'order.cross', title: __('Order.cross'), operate: 'LIKE'},
                        {field: 'order.amount', title: __('Order.amount'), operate:'BETWEEN'},
                        {field: 'order.ontime', title: __('Order.ontime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.status', title: __('Order.status')},
                        {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
                        {field: 'admin.invite', title: __('Admin.invite'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'info',
                                    text: __(''),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-eye',
                                    url: 'extension/goods/info',

                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});